package com.ptrsystem.siatd.controllers;

import com.ptrsystem.siatd.beans.TipoUsuarioExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.ptrsystem.siatd.dao.logica.MantenimientoTipUsuarioExtLogica;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TipoUsuarioExtController {

    @Autowired
    private MantenimientoTipUsuarioExtLogica logica;

    @RequestMapping(value = "registrarTipoUsuarioExt.htm", method = RequestMethod.GET)
    private String registrarTipoUsuarioExt(HttpServletRequest req) {
        req.getSession(true).setAttribute("codTipUsuExt", String.valueOf(logica.getGeneraCodTipoUsuarioExt()));
        req.getSession(true).setAttribute("result", "Estado De Mantenimiento");
        return "Mantenimiento/NRegTipoUsuarioExt";
    }

    @RequestMapping(value = "registraTipoUsuarioExt.htm", method = RequestMethod.POST)
    private String registraTipoUsuarioExt(TipoUsuarioExt tipUsuExt, HttpServletRequest req) {
        tipUsuExt.setCodTipUsuExt(String.valueOf(logica.getGeneraCodTipoUsuarioExt()));

        boolean rt = logica.getRegistraTipUsuario(tipUsuExt);
        if (rt) {
            req.getSession(true).setAttribute("codTipUsuExt", String.valueOf(logica.getGeneraCodTipoUsuarioExt()));
            req.getSession(true).setAttribute("result", "Registro Efectuado");
        } else {
            req.getSession(true).setAttribute("result", "Registro No Efectuado");
        }
        return "Mantenimiento/NRegTipoUsuarioExt";
    }

}
